package com.gzkemays.music.controller;

import com.gzkemays.common.GResult;
import com.gzkemays.music.po.vo.MusicBasicInformationVo;
import com.gzkemays.music.service.MusicService;
import com.gzkemays.utils.GResultUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 前端控制器
 *
 * @author gzkemays
 * @since 2021-03-27
 */
@RestController
public class MusicController {
  @Resource MusicService musicService;

  @PostMapping("upload")
  public GResult upload(MusicBasicInformationVo vo) throws IOException {
    return GResult.init().code(200).msg("上传成功").data(musicService.upload(vo)).build();
  }

  @GetMapping("list")
  public GResult list() {
    return GResultUtils.OK(musicService.findMusicList());
  }

  @GetMapping("get/{id}")
  public GResult get(@PathVariable("id") int id) {
    return GResultUtils.OK(musicService.findUrlById(id));
  }
}
